home *** CD-ROM | disk | FTP | other *** search
/ Openstep 4.2 (Developer) / Openstep Developer 4.2.iso / NextDeveloper / Source / GNU / uucp / Uucp.framework / unix.subproj / mkdirs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-09  |  1.0 KB  |  58 lines

  1. /* mkdirs.c
  2.    Create any directories needed for a file name.  */
  3.  
  4. #include "uucp.h"
  5.  
  6. #include "uudefs.h"
  7. #include "sysdep.h"
  8. #include "system.h"
  9.  
  10. #include <errno.h>
  11.  
  12. boolean
  13. fsysdep_make_dirs (zfile, fpublic)
  14.      const char *zfile;
  15.      boolean fpublic;
  16. {
  17.   char *zcopy, *z;
  18.   int imode;
  19.  
  20.   zcopy = zbufcpy (zfile);
  21.  
  22.   if (fpublic)
  23.     imode = IPUBLIC_DIRECTORY_MODE;
  24.   else
  25.     imode = IDIRECTORY_MODE;
  26.  
  27.   for (z = zcopy; *z != '\0'; z++)
  28.     {
  29.       if (*z == '/' && z != zcopy)
  30.     {
  31.       /* Some versions of uuto will send a double slash.  Some
  32.              systems will fail to create a directory ending in a
  33.              slash.  */
  34.       if (z[-1] == '/')
  35.         continue;
  36.       *z = '\0';
  37.       if (mkdir (zcopy, imode) != 0
  38.           && errno != EEXIST
  39.           && errno != EISDIR
  40. #ifdef EROFS
  41.           && errno != EROFS
  42. #endif
  43.           && (errno != EACCES || ! fsysdep_directory (zcopy)))
  44.         {
  45.           ulog (LOG_ERROR, "mkdir (%s): %s", zcopy,
  46.             strerror (errno));
  47.           ubuffree (zcopy);
  48.           return FALSE;
  49.         }
  50.       *z = '/';
  51.     }
  52.     }
  53.  
  54.   ubuffree (zcopy);
  55.  
  56.   return TRUE;
  57. }
  58.